package com.itheima.health.resource.aliyunmessage;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

/**
 * 短信发送工具类
 */
public class SMSUtils {

	public  static  String accessKeyId = "LTAI4G8NP84yxD2yEhcHyX6t";
	public  static String accessKeySecret = "qD6jmL573b6IbpFLEUQVIjmy5eZvD4";

	public static final String VALIDATE_CODE = "SMS_200704673";//发送短信验证码
	public static final String ORDER_NOTICE = "SMS_200704673";//体检预约成功通知


	/**
	 *   注册短信发送
	 */

	public  static  String  validaCodeSms(String telephone,String randomCode){
		try {
		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
		IAcsClient client = new DefaultAcsClient(profile);

		CommonRequest request = new CommonRequest();
		request.setSysMethod(MethodType.POST);
		request.setSysDomain("dysmsapi.aliyuncs.com");
		request.setSysVersion("2017-05-25");
		request.setSysAction("SendSms");
		request.putQueryParameter("RegionId", "cn-hangzhou");
		request.putQueryParameter("PhoneNumbers", telephone);
		request.putQueryParameter("SignName", "狗子健康");
		request.putQueryParameter("TemplateCode", VALIDATE_CODE);
		//   模板里面 ${code}
		request.putQueryParameter("TemplateParam", "{\"code\":\""+randomCode+"\"}");

			CommonResponse response = client.getCommonResponse(request);
			System.out.println(response.getData());
			String data = response.getData();
			return data;
		} catch (Exception e) {
			e.printStackTrace();
			throw  new RuntimeException("短信发送失败："+e.getMessage());
		}

	}




	/**
	 * 预约套餐成功 发送短信通知
	 */
	public  static  String  sendMessageTuYou(String telephone,String message){
		try {
			DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
			IAcsClient client = new DefaultAcsClient(profile);

			CommonRequest request = new CommonRequest();
			request.setSysMethod(MethodType.POST);
			request.setSysDomain("dysmsapi.aliyuncs.com");
			request.setSysVersion("2017-05-25");
			request.setSysAction("SendSms");
			request.putQueryParameter("RegionId", "cn-hangzhou");
			request.putQueryParameter("PhoneNumbers", telephone);
			request.putQueryParameter("SignName", "狗子健康");
			request.putQueryParameter("TemplateCode", ORDER_NOTICE);
			//   模板里面 ${code}
			request.putQueryParameter("TemplateParam", "{\"submittime\":\""+message+"\"}");

			CommonResponse response = client.getCommonResponse(request);
			System.out.println(response.getData());
			String data = response.getData();
			return data;
		} catch (Exception e) {
			e.printStackTrace();
			throw  new RuntimeException("预约短信发送失败："+e.getMessage());
		}

	}

}
